<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>增加电子文档</title>
  <style>
    body {
      font-family: Arial, sans-serif;
    }
    .form-container {
      width: 500px;
      margin: 20px auto;
      border: 1px solid #000;
      padding: 20px;
      background-color: #e0f7e9;
    }
    .form-container h2 {
      text-align: center;
    }
    .form-group {
      display: flex;
      margin-bottom: 15px;
    }
    .form-group label {
      width: 80px;
      text-align: right;
      margin-right: 10px;
    }
    .form-group input[type="text"],
    .form-group select,
    .form-group textarea {
      flex: 1;
      padding: 5px;
    }
    .form-group textarea {
      resize: none;
    }
    .form-group input[type="date"] {
      width: 150px;
    }
    .form-actions {
      text-align: center;
    }
    .form-actions input[type="submit"],
    .form-actions input[type="button"] {
      padding: 5px 20px;
      margin: 5px;
    }
  </style>
</head>
<body>

<div class="form-container">
  <h2>增加电子文档</h2>
  <form method="post">
    <div class="form-group">
      <label for="doc-name">文档名称 (*)</label>
      <input type="text" id="doc-name" name="doc-name" required>
    </div>
    <div class="form-group">
      <label for="doc-category">文档分类</label>
      <select id="doc-category" name="doc-category">
        <option value="全部">全部</option>
        <!-- 其他选项可以在这里添加 -->
      </select>
    </div>
    <div class="form-group">
      <label for="doc-summary">文档摘要</label>
      <textarea id="doc-summary" name="doc-summary" rows="4"></textarea>
    </div>
    <div class="form-group">
      <label for="uploader">上传人</label>
      <input type="text" id="uploader" name="uploader">
    </div>
    <div class="form-group">
      <label for="upload-date">上传时间 (*)</label>
      <input type="date" id="upload-date" name="upload-date" required>
    </div>
    <div class="form-actions">
      <input type="button" id="tj" value="提交">
      <input type="button" value="返回">
    </div>
  </form>
</div>

</body>
<script src="js/jquery-1.12.4.js"></script>
<script>
  $.get("http://localhost:8080/ElectronicDocumentManagementSystem/categor/sel", function (data) {
    console.log(data);
    $.each(data, function (index, item) {
      console.log(item);
      var html = `
                <option value="${item.id}">${item.name}</option>
                `
      ;$("select").append(html);
    })
  })
  $("#tj").click(function () {
    var entr = {
      categoryid:$("#doc-category").val(),
      title:$("#doc-name").val(),
      summar:$("#doc-summary").val(),
      docCategory:$("#doc-category").val(),
      uploaduser:$("#uploader").val(),
      createdate:$("#upload-date").val()
    }
    $.ajax(`http://localhost:8080/ElectronicDocumentManagementSystem/entr/addEntr`,{
      type: "post",
      dataType: "json",
      contentType: "application/json;charset=utf-8",
      data:JSON.stringify(entr),
      success: function (data) {
        console.log(entr)
        if (data.code == 200) {
          alert("添加成功")
          window.location.href = "index.html"
        }else {
          alert("添加失败")
        }
      }
    })
  })
</script>
</html>